const router = require('koa-router')()
router.prefix('/api/goods')
const { Goods, Category } = require('@model/super.js')
const { SuccessModel } = require('@model/resModel')

router.get('/list', async (ctx, next) => {
  const goodsList = await Goods.findAll({ include: Category })
  ctx.body = new SuccessModel(goodsList, ctx.requestApi)
})

router.post('/create', async (ctx, next) => {
  const { title, categoryId } = ctx.request.body
  const res = await Goods.create({
    title,
    categoryId
  })
  ctx.body = res
})

module.exports = router